package com.pmpd.activity.service.background.impl;

import com.pmpd.activity.dao.HotActivityTagMapper;
import com.pmpd.activity.po.HotActivityTag;
import com.pmpd.activity.po.HotActivityTagExample;
import com.pmpd.activity.service.background.BgHotActivityTagService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * \* User: helei
 * \* Date: 19/06/18
 * \* Description:
 * \
 */
@Service
public class BgHotActivityTagServiceImpl implements BgHotActivityTagService {

    @Resource
    private HotActivityTagMapper hotActivityTagMapper;

    @Override
    public HotActivityTag insert(HotActivityTag param) {
        param.setCreateTime(System.currentTimeMillis() / 1000);
        param.setUpdateTime(param.getCreateTime());
        int success = hotActivityTagMapper.insertSelective(param);
        return (success == 1) ? param : null;
    }

    @Override
    public boolean deleteByHotActivityId(Long hotActivityId) {
        HotActivityTagExample example = new HotActivityTagExample();
        example.createCriteria().andHotActivityIdEqualTo(hotActivityId);
        return hotActivityTagMapper.deleteByExample(example) > 0;
    }

    @Override
    public boolean deleteByHotActivityIdList(List<Long> hotActivityIdList) {
        HotActivityTagExample example = new HotActivityTagExample();
        example.createCriteria().andHotActivityIdIn(hotActivityIdList);
        return hotActivityTagMapper.deleteByExample(example) > 0;
    }

    @Override
    public List<HotActivityTag> selectByHotActivityId(Long hotActivityId) {
        HotActivityTagExample example = new HotActivityTagExample();
        example.createCriteria().andHotActivityIdEqualTo(hotActivityId);
        return hotActivityTagMapper.selectByExample(example);
    }

    @Override
    public int countByTagId(Long tagId) {
        HotActivityTagExample example = new HotActivityTagExample();
        example.createCriteria().andTagIdEqualTo(tagId);
        return hotActivityTagMapper.countByExample(example);
    }

}